/**
 * @class HPOLegend
 * @constructor
 */
var HPOLegend = Class.create( Legend, {

    initialize: function($super) {
        $super("表型", true);

        this._termCache = {};
    },

    _getPrefix: function(id) {
        return "phenotype";
    },

    /**
     * @method getTerm
     * @return {Object}
     */
    getTerm: function(hpoID) {
        hpoID = HPOTerm.sanitizeID(hpoID);
        if (!this._termCache.hasOwnProperty(hpoID)) {
            var whenNameIsLoaded = function() { this._updateTermName(hpoID); }
            this._termCache[hpoID] = new HPOTerm(hpoID, null, whenNameIsLoaded.bind(this));
        }
        return this._termCache[hpoID];
    },

    /**
     *
     * @method getObjectColor
     * @param {String|Number} id 
     * @return {String}
     */
    getObjectColor: function(id) {
        return "#CCCCCC";
    },

    /**
     *
     * @method addCase
     * @param {Number|String} id 
     * @param {String} name 
     * @param {Number} nodeID 
     */
    addCase: function($super, id, name, nodeID) {
        if (!this._termCache.hasOwnProperty(id))
            this._termCache[id] = new HPOTerm(id, name);

        $super(id, name, nodeID);
    },

    /**
     *
     * @method _updateTermName
     * @param {Number} id 
     * @private
     */
    _updateTermName: function(id) {
        var name = this._legendBox.down('li#' + this._getPrefix() + '-' + id + ' .disorder-name');
        name.update(this.getTerm(id).getName());
    },

    /**
     *
     * @method _onDropGeneric
     * @param {Person} Person node
     * @param {String|Number} id 
     */
    _onDropObject: function(node, hpoID) {
        if (node.isPersonGroup()) {
            return;
        }
        var currentHPO = node.getHPO().slice(0);
        if (currentHPO.indexOf(hpoID) == -1) {
            currentHPO.push(hpoID);
            editor.getView().unmarkAll();
            var properties = { "setHPO": currentHPO };
            var event = { "nodeID": node.getID(), "properties": properties };
            document.fire("pedigree:node:setproperty", event);
        } else {
            alert("This person already has the selected phenotype");
        }
    },
});
